//by 略游

_weathers = [];


fn_setWeather = 
{
	private _dt = (_this select 5);
	_dt setOvercast (_this select 0); 
	_dt setrain (_this select 1);
	_dt setfog (_this select 2);
	_dt setlightnings (_this select 3);
	
	//随机方向转为分量
	_d = _this select 4;
	if(_d > 0) then
	{
		_r = random 360;
		_vx = (_this select 4) * cos _r;
		_vy = (_this select 4) * sin _r;
		setWind [_vx, _vy, true];
	}
	else
	{
		setWind [0, 0, true];
	};
};

//晴朗 0
_weathers pushBack [0, 0, 0, 0, 1];//阴晴 雨 雾 雷电 风

//阴天 1
_weathers pushBack [0.6, 0, 0, 0, 2];

//雨天 2
_weathers pushBack [0.8, 0.4, 0, 0, 4];

//暴雨 3
_weathers pushBack [1.0, 0.6, 0, 1, 6];

//大雾 4
_weathers pushBack [0.3, 0, 1.0, 0, 0];

//中雾 5
_weathers pushBack [0.2, 0, 0.8, 0, 0];

//太阳雨 6
_weathers pushBack [0.1, 0.4, 0, 0, 0];

_weathersOnes = [];
if(Param_Weather != -1)exitWith
{
	_weathersOnes = _weathers select Param_Weather;
	_weathersOnes pushBack 0;
	_weathersOnes call fn_setWeather;
	forceWeatherChange;
};

_lastWeather = 0;
fn_setWeather2 = 
{
	params["_index", "_h"];
	_lastWeather = _index;
	_weathersOnes = _weathers select _index;
	_weathersOnes pushBack (_h * 150) * Param_TimeMultiplier;
	
	if(Param_Debug == 1) then
	{
		systemChat format["weather: %1,%2", _index, _h];
	};
	
	_weathersOnes spawn fn_setWeather;
};


//一天
while{true} do
{
	waitUntil{sleep 10;daytime > 4};
	//黎明趋向于晴朗 或大雾
	if(random 100 < 50) then
	{
		[0, 2] call fn_setWeather2;
	}
	else
	{
		if(random 100 < 50) then
		{
			[2, 2] call fn_setWeather2;//雨天
		}
		else
		{
			if(random 100 < 25) then
			{
				[4, 2] call fn_setWeather2;//大雾
			}
			else
			{
				[5, 2] call fn_setWeather2;//中雾
			};
		};
	};
	waitUntil{sleep 10;daytime > 7};
	//上午趋向 太阳雨 或晴朗
	private _rainRR = 33;
	if(_lastWeather == 5) then{_rainRR = _rainRR + 33};
	if(random 100 < _rainRR) then
	{
		[6, 2] call fn_setWeather2;
	}
	else
	{
		[0, 2] call fn_setWeather2;
	};

	waitUntil{sleep 10;daytime > 10};
	//中午大概率晴朗
	if(random 100 < 85) then
	{
		[0, 2] call fn_setWeather2;
	}
	else
	{
		[2, 2] call fn_setWeather2;
	};
	
	waitUntil{sleep 10;daytime > 13};
	//下午继续晴朗或阴天，微小概率下雨
	if(random 100 < 60) then
	{
		if(random 100 < 20) then
		{
			[2, 2] call fn_setWeather2;
		}
		else
		{
			[1, 2] call fn_setWeather2;
		};
	}
	else
	{
		[0, 2] call fn_setWeather2;
	};
	
	waitUntil{sleep 10;daytime > 16};
	//黄昏可能会下雨
	_rainRR = 25;
	if(_lastWeather == 1) then{_rainRR = _rainRR + 25};
	if(random 100 < _rainRR) then
	{
		[2, 2] call fn_setWeather2;
	}
	else
	{
		[0, 2] call fn_setWeather2;
	};
	
	
	waitUntil{sleep 10;daytime > 19};
	//入夜后有概率下暴雨
	_rainRR = 20;
	if(_lastWeather == 2) then{_rainRR = _rainRR + 30};
	if(random 100 < _rainRR) then
	{
		[3, 2] call fn_setWeather2;
	}
	else
	{
		[0, 2] call fn_setWeather2;
	};
	
	waitUntil{sleep 10;daytime > 22};
	//午夜 会阴暗 会明亮 或者继续下雨
	_rainRR = 50;
	if(_lastWeather == 3) then{_rainRR = _rainRR + 20};
	if(random 100 < _rainRR) then
	{
		[0, 2] call fn_setWeather2;
	}
	else
	{
		if(random 100 < 40) then
		{
			[3, 2] call fn_setWeather2;
		}
		else
		{
			[1, 2] call fn_setWeather2;
		};
	};
	
};
